package packing;

/**
 * 包装类测试
 */
public class myTest {

    public static void main(String[] args) {

        // Integer、Long 127以内会被缓存，从常量池取
        Long a1 = 200l;
        Long a2 = 200l;
        Long a3 = 100l;
        Long a4 = 100l;
        System.out.println("a1 == a2：" + (a1 == a2));
        System.out.println("a3 == a4：" + (a3 == a4));


        // new 就是新对象
        Integer b1 = 200;
        Integer b2 = new Integer(b1);
        Integer b3 = 100;
        Integer b4 = new Integer(b3);
        System.out.println("b1 == b2：" + (b1 == b2));
        System.out.println("b3 == b4：" + (b3 == b4));

        // 包装类为final，运算会new一个新的，而127以内的不会new
        Integer c1 = 200;
        Integer c2 = c1 + 1 - 1;
        Integer c3 = c1 + 0;
        Integer c4 = 100;
        Integer c5 = c4 + 1 - 1;
        Integer c6 = c4 + 0;
        System.out.println("c1 == c2：" + (c1 == c2));
        System.out.println("c1 == c3：" + (c1 == c3));
        System.out.println("c4 == c5：" + (c4 == c5));
        System.out.println("c4 == c6：" + (c4 == c6));

    }
}
